#!/bin/bash
# 备份Postgresql数据库。pg数据库运行在docker容器中

# 获取pg容器id
cid=$(docker ps -q --filter status=running --filter name=db_db_1)

if [ ! $cid ]; then
    echo "Container id not found!!!!"
else
    echo "start to backup pg db, container id: $cid"
    docker exec -u postgres $cid bash -c 'cd $PGDATA && pg_dumpall -v | bzip2 -vf > "pgdumpall_$(date +%Y%m%d).bz2"'
fi